package edu.wan.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

//JSON公共处理工具
public class JSONUtil {
    //同类一起加载
    private static  ObjectMapper objectMapper = new ObjectMapper();

    //把对象转换成Json串
    public String serial(Object obj) throws JsonProcessingException {
       return objectMapper.writeValueAsString(obj);
    }

    //把String类型转换成对象
    public <T> T deserial(String str,Class<T> clazz) throws IOException {
        T t = objectMapper.readValue(str, clazz);
        return t;
    }
}
